<template>
  <div class="line-echart">
    <base-echart :options="options"></base-echart>
  </div>
</template>

<script setup>
import { computed } from '@vue/runtime-core'
import BaseEchart from '../base-echart.vue'

const props = defineProps({
  title: String,
  xLabels: Array,
  values: Array
})

const options = computed(() => {
  return {
    title: {
      text: props.title
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        label: {
          backgroundColor: '#6a7985'
        }
      }
    },
    legend: {},
    toolbox: {
      feature: {
        saveAsImage: {}
      }
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: [
      {
        type: 'category',
        // boundaryGap: false,
        data: props.xLabels
      }
    ],
    yAxis: [
      {
        type: 'value',
        axisLabel: {
          formatter: '{value} °C'
        },
        // y坐标刻度上为最高值和最低值+2
        min: function (value) {
          if (value.min % 2 === 0) {
            return value.min - 2
          } else {
            return value.min - 1
          }
        },
        max: function (value) {
          if (value.max % 2 === 0) {
            return value.max + 2
          } else {
            return value.max + 1
          }
        }
      }
    ],
    series: [
      {
        name: '24小时预报',
        type: 'line',
        stack: '总量',
        // areaStyle: {},
        emphasis: {
          focus: 'series'
        },
        data: props.values
      }
    ]
  }
})
</script>

<style lang="less" scoped></style>
